package cn.arnold.offer.crip;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class WordsInstead {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String word = scan.nextLine();
        String words = scan.nextLine();
        String insteadWord = scan.nextLine();
        int n = word.length();
        // 记录逗号出现的位置
        List<Integer> index = new ArrayList<Integer>();
        for (int i = 0; i < words.length(); i++) {
            char ch = words.charAt(i);
            if (ch == ','){
                index.add(i);
            }
        }
        String temp = words.replaceAll(",", " ");
        String[] split = temp.split(" ", -1);
        for (int i = 0; i < split.length; i++) {
            int count = 0;
            if (n != split[i].length()){
                continue;
            }else {
                for (int j = 0; j < n; j++) {
                    if (word.contains(split[i].charAt(j)+"")){
                        count++;
                    }
                }
                // 替换
                if (count == n){
                    split[i] = insteadWord;
                }
            }
        }
        // 还原
        StringBuilder sb = new StringBuilder();
        for (String s : split) {
            sb.append(s);
            sb.append(" ");
        }
        for (Integer integer : index) {
            sb.setCharAt(integer+1,',');
        }
        System.out.println(sb.toString());

    }


}
